package com.jeff.springbootdemo;

import com.jeff.springbootdemo.bean.Student;
import com.jeff.springbootdemo.bean.Teacher;
import com.jeff.springbootdemo.config.MainConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

@SpringBootApplication
public class MainApplication {

    public static void main(String[] args) {

        ConfigurableApplicationContext context = SpringApplication.run(MainApplication.class, args);

        Student student = context.getBean("student",Student.class);
        Teacher teacher = context.getBean("teacher",Teacher.class);

        System.out.println(student);
        System.out.println(teacher);
        System.out.println(student.getTeacher() == teacher);


        MainConfig config = context.getBean(MainConfig.class);
        Teacher methodTeacher = config.teacher();
        System.out.println(student.getTeacher() == methodTeacher);

        System.out.println("==============");
        for (String s : context.getBeanNamesForType(Student.class)) {
            System.out.println(s);
        }



        System.out.println("包含teacher01组件" + context.containsBean("teacher01"));
        System.out.println("包含XmlStudent组件" + context.containsBean("XmlStudent"));

        System.out.println(context.getBean("XmlStudent",Student.class));
    }

}
